package com.exam.controller;
import com.exam.entity.TrainingQuestionSet;
import com.exam.service.TrainingQuestionSetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;
//根据课程生成训练题
@RestController
@RequestMapping("/api/training-sets")
public class TrainingQuestionSetController {

    @Autowired
    private TrainingQuestionSetService trainingQuestionSetService;

    @PostMapping("/generate")
    public TrainingQuestionSet generateTrainingSet(
            @RequestParam String course,
            @RequestParam int fillQuestionCount,
            @RequestParam int multiQuestionCount,
            @RequestParam int judgeQuestionCount
    ) {
        return trainingQuestionSetService.generateTrainingSet(course, fillQuestionCount, multiQuestionCount, judgeQuestionCount);
    }

    @GetMapping("/{id}")
    public TrainingQuestionSet getTrainingSetById(@PathVariable Long id) {
        return trainingQuestionSetService.getTrainingSetById(id);
    }

    @GetMapping("/paged")
    public Page<TrainingQuestionSet> getAllTrainingSetsPaged(
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "10") int size
    ) {
        Pageable pageable = PageRequest.of(page, size);
        return trainingQuestionSetService.getAllTrainingSets(pageable);
    }

    @DeleteMapping("/{id}")
    public void deleteTrainingSet(@PathVariable Long id) {
        trainingQuestionSetService.deleteTrainingSet(id);
    }
}